﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _2_6
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void label2_Click(object sender, EventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            // 转换起始年份和结束年份为int类型
            int startYear = int.Parse(textBox1.Text);
            int endYear = int.Parse(textBox2.Text);
            string leapYears = ""; // 存储所有闰年，用\t分隔

            // for循环遍历年份范围
            for (int year = startYear; year <= endYear; year++)
            {
                // 闰年判断条件：能被4整除且不能被100整除，或能被400整除
                bool isLeapYear = (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);

                if (isLeapYear)
                {
                    leapYears += year.ToString() + "\t"; // 闰年用制表符分隔，便于对齐
                }
            }

            // 显示所有闰年
            textBox3.Text = leapYears;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // 获取当前年份，转为字符串填充到textBox2
            textBox2.Text = DateTime.Now.Year.ToString();
        }
    }
}
